import 'package:flutter_book_store/beans/books_entity.dart';

booksEntityFromJson(BooksEntity data, Map<String, dynamic> json) {
	if (json['total'] != null) {
		data.total = json['total'] is String
				? int.tryParse(json['total'])
				: json['total'].toInt();
	}
	if (json['list'] != null) {
		data.xList = new List<BooksList>();
		(json['list'] as List).forEach((v) {
			data.xList.add(new BooksList().fromJson(v));
		});
	}
	if (json['pageNum'] != null) {
		data.pageNum = json['pageNum'] is String
				? int.tryParse(json['pageNum'])
				: json['pageNum'].toInt();
	}
	if (json['pageSize'] != null) {
		data.pageSize = json['pageSize'] is String
				? int.tryParse(json['pageSize'])
				: json['pageSize'].toInt();
	}
	if (json['size'] != null) {
		data.size = json['size'] is String
				? int.tryParse(json['size'])
				: json['size'].toInt();
	}
	if (json['startRow'] != null) {
		data.startRow = json['startRow'] is String
				? int.tryParse(json['startRow'])
				: json['startRow'].toInt();
	}
	if (json['endRow'] != null) {
		data.endRow = json['endRow'] is String
				? int.tryParse(json['endRow'])
				: json['endRow'].toInt();
	}
	if (json['pages'] != null) {
		data.pages = json['pages'] is String
				? int.tryParse(json['pages'])
				: json['pages'].toInt();
	}
	if (json['prePage'] != null) {
		data.prePage = json['prePage'] is String
				? int.tryParse(json['prePage'])
				: json['prePage'].toInt();
	}
	if (json['nextPage'] != null) {
		data.nextPage = json['nextPage'] is String
				? int.tryParse(json['nextPage'])
				: json['nextPage'].toInt();
	}
	if (json['isFirstPage'] != null) {
		data.isFirstPage = json['isFirstPage'];
	}
	if (json['isLastPage'] != null) {
		data.isLastPage = json['isLastPage'];
	}
	if (json['hasPreviousPage'] != null) {
		data.hasPreviousPage = json['hasPreviousPage'];
	}
	if (json['hasNextPage'] != null) {
		data.hasNextPage = json['hasNextPage'];
	}
	if (json['navigatePages'] != null) {
		data.navigatePages = json['navigatePages'] is String
				? int.tryParse(json['navigatePages'])
				: json['navigatePages'].toInt();
	}
	if (json['navigatepageNums'] != null) {
		data.navigatepageNums = json['navigatepageNums']?.map((v) => v is String
				? int.tryParse(v)
				: v.toInt())?.toList()?.cast<int>();
	}
	if (json['navigateFirstPage'] != null) {
		data.navigateFirstPage = json['navigateFirstPage'] is String
				? int.tryParse(json['navigateFirstPage'])
				: json['navigateFirstPage'].toInt();
	}
	if (json['navigateLastPage'] != null) {
		data.navigateLastPage = json['navigateLastPage'] is String
				? int.tryParse(json['navigateLastPage'])
				: json['navigateLastPage'].toInt();
	}
	return data;
}

Map<String, dynamic> booksEntityToJson(BooksEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['total'] = entity.total;
	if (entity.xList != null) {
		data['list'] =  entity.xList.map((v) => v.toJson()).toList();
	}
	data['pageNum'] = entity.pageNum;
	data['pageSize'] = entity.pageSize;
	data['size'] = entity.size;
	data['startRow'] = entity.startRow;
	data['endRow'] = entity.endRow;
	data['pages'] = entity.pages;
	data['prePage'] = entity.prePage;
	data['nextPage'] = entity.nextPage;
	data['isFirstPage'] = entity.isFirstPage;
	data['isLastPage'] = entity.isLastPage;
	data['hasPreviousPage'] = entity.hasPreviousPage;
	data['hasNextPage'] = entity.hasNextPage;
	data['navigatePages'] = entity.navigatePages;
	data['navigatepageNums'] = entity.navigatepageNums;
	data['navigateFirstPage'] = entity.navigateFirstPage;
	data['navigateLastPage'] = entity.navigateLastPage;
	return data;
}

booksListFromJson(BooksList data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'].toString();
	}
	if (json['isbn'] != null) {
		data.isbn = json['isbn'] is String
				? int.tryParse(json['isbn'])
				: json['isbn'].toInt();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['author'] != null) {
		data.author = json['author'].toString();
	}
	if (json['type'] != null) {
		data.type = json['type'].toString();
	}
	if (json['status'] != null) {
		data.status = json['status'];
	}
	if (json['synopsis'] != null) {
		data.synopsis = json['synopsis'].toString();
	}
	if (json['level'] != null) {
		data.level = json['level']?.map((v) => v is String
				? int.tryParse(v)
				: v.toInt())?.toList()?.cast<int>();
	}
	if (json['isClick'] != null) {
		data.isClick = json['isClick'];
	}
	return data;
}

Map<String, dynamic> booksListToJson(BooksList entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['isbn'] = entity.isbn;
	data['name'] = entity.name;
	data['author'] = entity.author;
	data['type'] = entity.type;
	data['status'] = entity.status;
	data['synopsis'] = entity.synopsis;
	data['level'] = entity.level;
	data['isClick'] = entity.isClick;
	return data;
}